BX.namespace("BX.Main");if(typeof BX.Main.pin==="undefined"){BX.Main.pin=function(t){this.container=t;this.defaultOptions={pinTop:{dataKey:"pin-top",defaultValue:false},pinBottom:{dataKey:"pin-bottom",defaultValue:false},pinClass:{dataKey:"pin-class",defaultValue:"bx-pinned"},pinTopClass:{dataKey:"pin-top-class",defaultValue:"bx-pinned-top"},pinBottomClass:{dataKey:"pin-bottom-class",defaultValue:"bx-pinned-bottom"},pinUseControll:{dataKey:"pin-use-controll",defaultValue:false},pinControllClass:{dataKey:"pin-controll-class",defaultValue:"bx-pin-controll"},pinControllPinClass:{dataKey:"pin-controll-pin-class",defaultValue:"bx-pin-controll-pin"},pinControllUnpinClass:{dataKey:"pin-controll-unpin-class",defaultValue:"bx-pin-controll-unpin"},offsetTop:{dataKey:"pin-offset-top",defaultValue:0},offsetBottom:{dataKey:"pin-offset-bottom",defaultValue:0},idPrefix:{dataKey:"pin-id-prefix",defaultValue:"bxpin"},useOuterWidth:{dataKey:"pin-use-outer-width",defaultValue:""},useInnerWidth:{dataKey:"pin-use-inner-width",defaultValue:""},niceAttachment:{dataKey:"pin-use-nice-attachment",defaultValue:true}};this.settings=null;this.controll=null;this.cache={};this.init()};BX.Main.pin.prototype={init:function(){this.prepareSettings();this.makeControll();this.bindOnClickControll();this.adjustPosition();this.bindOnScrollWindow();this.bindOnResizeWindow()},prepareSettings:function(){var t=Object.keys(this.defaultOptions);var i={};var n=null;var e=this;t.forEach(function(t){n=BX.data(e.container,e.defaultOptions[t].dataKey);n=n==="true"?true:n;n=n==="false"?false:n;i[t]=n?n:e.defaultOptions[t].defaultValue});this.settings=i},makeControll:function(){var t=null;var i="";if(this.settings.pinUseControll){i=[this.settings.pinControllClass,this.getUserPinState()?this.settings.pinControllPinClass:this.settings.pinControllUnpinClass].join(" ");t=BX.create("span",{props:{className:i}});this.container.appendChild(t);this.controll=t}},bindOnClickControll:function(){BX.bind(this.controll,"click",BX.delegate(this._onClickControll,this))},bindOnScrollWindow:function(){BX.bind(window,"scroll",BX.delegate(this._onScroll,this))},bindOnResizeWindow:function(){BX.bind(window,"resize",BX.delegate(this._onResize,this))},getScrollTopPosition:function(){return BX.scrollTop(window)},getParentRect:function(){return BX.pos(this.container.parentNode)},getContainerRect:function(){var t=this.getCache("getContainerRect");if(!t){t=BX.pos(this.container);this.setCache("getContainerRect",t)}return t},getContainerWidth:function(){var t=this.getCache("getContainerWidth");if(!t){t=BX.width(this.container);this.setCache("getContainerWidth",t)}return t},setContainerWidth:function(t){this.setCache("getContainerWidth",t);BX.width(this.container,t+"px")},getCache:function(t){if(!t){return}return this.cache[t]?this.cache[t]:null},setCache:function(t,i){return this.cache[t]=i},getStyleProperty:function(t,i){var n=document.styleSheets;var e=this.getCache("getStyleProperty");if(!e){for(var s=0,o=n.length;s<o;s++){var a=n[s];if(!a.cssRules){continue}for(var l=0,r=a.cssRules.length;l<r;l++){var h=a.cssRules[l];if(h.selectorText&&h.selectorText.split(",").indexOf(i)!==-1){e=h.style[t].replace("px","")}}}this.setCache("getStyleProperty",e)}return e},pin:function(t,i){var n=null;var e;var s=t==this.settings.pinTopClass?"top":"bottom";var o=this.getParentWidth();var a;if(i){e=this.getStyleProperty(s,"."+t);e=s=="top"?parseFloat(e)+parseFloat(i):parseFloat(e)-parseFloat(i)}BX.addClass(this.container,t);BX.style(this.container,s,e+"px");BX.style(this.container,"width",o+"px");if(this.settings.niceAttachment){a=BX.height(this.container);this.fake=BX.create("div",{style:{opacity:0,height:a+"px"}});this.container.parentNode.appendChild(this.fake);this.container.parentNode.insertBefore(this.fake,this.container)}},unpin:function(){BX.remove(this.fake);BX.removeClass(this.container,this.settings.pinTopClass);BX.removeClass(this.container,this.settings.pinBottomClass);this.container.removeAttribute("style")},adjustPosition:function(){var t,i;if(this.settings.pinUseControll&&!this.getUserPinState()){return}t=this.getContainerRect();i=this.getScrollTopPosition();if(this.settings.pinTop&&i>=t.top-this.settings.offsetTop){if(!this.isPinned()){this.pin(this.settings.pinTopClass,this.settings.offsetTop)}}if(this.settings.pinTop&&i<=t.top-this.settings.offsetTop){if(this.isPinned()){this.unpin()}}if(this.settings.pinBottom&&i+BX.height(window)>=t.bottom-this.settings.offsetBottom){if(!this.isPinned()){this.pin(this.settings.pinBottomClass,this.settings.offsetBottom)}}if(this.settings.pinBottom&&i+BX.height(window)<=t.bottom-this.settings.offsetBottom){if(this.isPinned()){this.unpin()}}},isPinned:function(){return BX.hasClass(this.container,this.settings.pinTopClass)||BX.hasClass(this.container,this.settings.pinBottomClass)},getId:function(){var t=null;if(BX.type.isNotEmptyString(this.container.id)){t=this.settings.idPrefix+this.container.id}return t},setUserPinState:function(t){var i;if(!window.localStorage){}i=this.getId();window.localStorage.setItem(i,JSON.stringify(t))},getUserPinState:function(){var t;if(!window.localStorage){return}t=this.getId();return JSON.parse(window.localStorage.getItem(t))},getParentWidth:function(){var t,i,n,e,s;if(BX.type.isNotEmptyString(this.settings.useOuterWidth)&&!BX.type.isNotEmptyString(this.settings.useInnerWidth)){e=BX.findParent(this.container,{"class":this.settings.useOuterWidth});t=BX.width(e)}else{s=BX.findParent(this.container,{"class":this.settings.useInnerWidth});t=parseFloat(BX.width(s));i=parseFloat(BX.style(s,"padding-left"));n=parseFloat(BX.style(s,"padding-right"));t=t-(i+n)}if(!BX.type.isNotEmptyString(this.settings.useOuterWidth)&&!BX.type.isNotEmptyString(this.settings.useInnerWidth)){t=BX.width(this.container.parentNode);i=parseFloat(BX.style(this.container.parentNode,"padding-left"));n=parseFloat(BX.style(this.container.parentNode,"padding-right"));t=t-(i+n)}return t},_onClickControll:function(t){if(BX.hasClass(this.controll,this.settings.pinControllPinClass)){BX.removeClass(this.controll,this.settings.pinControllPinClass);BX.addClass(this.controll,this.settings.pinControllUnpinClass);this.setUserPinState(false);this.unpin()}else{BX.addClass(this.controll,this.settings.pinControllPinClass);BX.removeClass(this.controll,this.settings.pinControllUnpinClass);this.setUserPinState(true)}},_onScroll:function(t){this.adjustPosition()},_onResize:function(t){var i;if(this.isPinned()){i=this.getParentWidth();this.setContainerWidth(i?i:this.getContainerWidth())}}};BX(function(){var t=BX.findChild(document,{"class":"bx-pin"},true,true);t.map(function(t){new BX.Main.pin(t)})})}
//# sourceMappingURL=pin.map.js